<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>

<script>

function confirmDelete() {
	var questions = $('listForm').ql_questions;
	var i = 0;
	for (; i < questions.length; i++) {
		if (questions[i].checked) {
			break;
		}
	}
	if (i < questions.length) {
		return confirm('Bạn có chắc muốn xóa (các) câu hỏi này?');
	}
	alert('Bạn cần chọn ít nhất 1 câu hỏi.');
	return false;
}

</script>

${message}

<form action="${scriptPath}" id="listForm">
<input type="hidden" name="action" value="question.list" />

<div class="toolbar">
<button name="ql_submit" value="create" type="submit">Thêm</button>
<button name="ql_submit" value="delete" type="submit" onclick="return validateDelete();">Xóa</button>
</div>

<div class="navigator">
<c:choose>
	<c:when test="${page > 1}">
		<a href="${scriptPath}?action=question.list&page=1">&lt;&lt;</a>
		<a href="${scriptPath}?action=question.list&page=${page-1}">&lt;</a>
	</c:when>
	<c:otherwise>
		&lt;&lt; 
		&lt; 
	</c:otherwise>
</c:choose>

Trang ${page}

<c:choose>
	<c:when test="${page < pageCount}">
		<a href="${scriptPath}?action=question.list&page=${page+1}">&gt;</a>
		<a href="${scriptPath}?action=question.list&page=${pageCount}">&gt;&gt;</a>
	</c:when>
	<c:otherwise>
		&gt;
		&gt;&gt;
	</c:otherwise>
</c:choose>
</div>

<table>
<tr>
	<td>&nbsp;</td>
	<td>Nội dung</td>
	<td>Thể loại</td>
	<td>Tác giả</td>
</tr>
<c:forEach items="${questions}" var="question">
<tr>
	<td><input type="checkbox" name="ql_questions" value="${question.id}"></input></td>
	<td>${question.content}
		<c:forEach items="${question.answers}" var="answer">
			<div><input type="checkbox" disabled 
				${answer.correct ? "checked" : ""}></input>${answer.content}</div>
		</c:forEach>
	</td>
	<td><a href="${scriptPath}?action=question.list&category=${question.category.id}">
		${question.category.name}
	</a></td>
	<td><a href="${scriptPath}?action=question.list&author=${question.author.id}">
		${question.author.name}
	</a></td>
</tr>
</c:forEach>
<tr>
</tr>
</table>

<div class="navigator">
<c:choose>
	<c:when test="${page > 1}">
		<a href="${scriptPath}?action=question.list&page=1">&lt;&lt;</a>
		<a href="${scriptPath}?action=question.list&page=${page-1}">&lt;</a>
	</c:when>
	<c:otherwise>
		&lt;&lt; 
		&lt; 
	</c:otherwise>
</c:choose>

Trang ${page}

<c:choose>
	<c:when test="${page < pageCount}">
		<a href="${scriptPath}?action=question.list&page=${page+1}">&gt;</a>
		<a href="${scriptPath}?action=question.list&page=${pageCount}">&gt;&gt;</a>
	</c:when>
	<c:otherwise>
		&gt;
		&gt;&gt;
	</c:otherwise>
</c:choose>
</div>

</form>